package com.iflysse.service;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.iflysse.dao.RoleMenuInfoDao;
import com.iflysse.pojo.MenuInfo;
import com.iflysse.pojo.RoleMenu;
import com.iflysse.utils.MySessionFactory;

public class RoleMenuService {

	private SqlSessionFactory sf;

	public RoleMenuService() {
		sf = MySessionFactory.getSessionFactory();
	}

	public void insertRoleMenu(RoleMenu rm) {
		SqlSession session = sf.openSession();
		RoleMenuInfoDao dao = session.getMapper(RoleMenuInfoDao.class);
		dao.insertRoleMenu(rm);
		session.commit();
		session.close();
	}

	public void deleteByRoleId(int rid) {
		SqlSession session = sf.openSession();
		RoleMenuInfoDao dao = session.getMapper(RoleMenuInfoDao.class);
		dao.delByRoleId(rid);
		session.commit();
		session.close();
	}
	
	//通过roleid 查找到对应的menu菜单
	public List<MenuInfo> findMenusByRoldId(int roleid){
//		SqlSession session = sf.openSession();
//		RoleMenuInfoDao dao = session.getMapper(RoleMenuInfoDao.class);
//		//1,根据roleid找到表中的对应的记录
//		List<RoleMenu> menuIdlist = dao.findRoleMenusByRoldId(roleid);
//		for(RoleMenu rm:menuIdlist){
//			int menuid = rm.getMenuid();
//			//2,通过menuid查找到对应表中记录
//		}
		MenuInfoService mis = new MenuInfoService();
		return mis.findMenusByRoleId(roleid);
	}

}
